/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import org.apt.Bean.PaymentLectureEntities;
import org.apt.connectDB.MyConnect;

/**
 *
 * @author Administrator
 */
public class PaymentLectureDao {

    public static boolean InsertPaymentLecture(PaymentLectureEntities paymentLecture) {
        boolean resuilt = false;
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            if (paymentLecture != null) {
                String sql = "insert into PaymentLecture values('" + paymentLecture.getUser() + "'," + paymentLecture.getEventID() + "," + paymentLecture.getGroupPaymentID() + ",'" + paymentLecture.isStatusPayment() + "','" + paymentLecture.isStatus() + "','" + paymentLecture.getDescription() + "')";
                con = MyConnect.getConnection();
                st = con.createStatement();
                int number = st.executeUpdate(sql);
                if (number > 0) {
                    resuilt = true;
                } else {
                    resuilt = true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyConnect.closeConntion(con, st, rs);
        }
        return resuilt;
    }

    public static PaymentLectureEntities getPaymentLectureByUserAndID(String user, int lectureID) {
        PaymentLectureEntities lecturePayment = new PaymentLectureEntities();
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        String sql = "Select * from PaymentLecture where [User] ='" + user + "' and EventID=" + lectureID + " ";
        try {
            con = MyConnect.getConnection();
            st = con.createStatement();
            rs = st.executeQuery(sql);
            while (rs.next()) {
                lecturePayment.setID(rs.getInt("ID"));
                lecturePayment.setUser(rs.getString("User"));
                lecturePayment.setEventID(rs.getInt("EventID"));
                lecturePayment.setGroupPaymentID(rs.getInt("GroupPaymentID"));
                lecturePayment.setStatusPayment(rs.getBoolean("StatusPayment"));
                lecturePayment.setStatus(rs.getBoolean("Status"));
                lecturePayment.setDescription(rs.getString("Description"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyConnect.closeConntion(con, st, rs);
        }
        return lecturePayment;
    }

    public static PaymentLectureEntities getPaymentLectureByLectureID(int lectureID) {
        PaymentLectureEntities lecturePayment = new PaymentLectureEntities();
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        String sql = "Select * from PaymentLecture where EventID=" + lectureID + " ";
        try {
            con = MyConnect.getConnection();
            st = con.createStatement();
            rs = st.executeQuery(sql);
            while (rs.next()) {
                lecturePayment.setID(rs.getInt("ID"));
                lecturePayment.setUser(rs.getString("User"));
                lecturePayment.setEventID(rs.getInt("EventID"));
                lecturePayment.setGroupPaymentID(rs.getInt("GroupPaymentID"));
                lecturePayment.setStatusPayment(rs.getBoolean("StatusPayment"));
                lecturePayment.setStatus(rs.getBoolean("Status"));
                lecturePayment.setDescription(rs.getString("Description"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyConnect.closeConntion(con, st, rs);
        }
        return lecturePayment;
    }

    public static void main(String[] args) {
        PaymentLectureEntities a = getPaymentLectureByLectureID(28);
        System.out.println(a.getID());
    }
}
